package com.sunny.springboot2.controller;

import com.battcn.swagger.properties.ApiDataType;
import com.battcn.swagger.properties.ApiParamType;
import com.sunny.springboot2.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * swagger测试controller
 * @author sunny
 * @date 2018/11/27
 */
@RestController
@RequestMapping("/noPer/users")
@Api(tags = "1.1", value = "用户管理")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @GetMapping("queryUser")
    @ApiOperation(value = "查询用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = ApiDataType.STRING, paramType = ApiParamType.QUERY),
            @ApiImplicitParam(name = "password", value = "密码", dataType = ApiDataType.STRING, paramType = ApiParamType.QUERY)})
    public User queryUser(String userName, String password) {
        logger.info("查询用户！！");
        return new User(1L, userName, password);
    }

    @GetMapping("queryUserById/{id}")
    @ApiOperation(value = "根据主键查询用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = ApiDataType.LONG, paramType = ApiParamType.PATH)})
    public User queryUserById(@PathVariable Long id) {
        logger.info("查询用户！！");
        return new User(id, "Sunny", "5625");
    }
}
